package controllers.Administrador;

import java.util.Collection;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import services.ActaService;
import controllers.AbstractController;
import domain.Acta;

@Transactional
@Controller
@RequestMapping("/acta/administrator")
public class ActaAdministratorController extends AbstractController {

	@Autowired
	private ActaService actaService;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public ModelAndView list(@RequestParam int comunidadId) {
		ModelAndView result;
		Collection<Acta> actas;

		actas = actaService.findActasByComunidadDeVecinos(comunidadId);

		result = new ModelAndView("acta/list");
		result.addObject("requestURI", "acta/administrator/list.do");
		result.addObject("actas", actas);
		result.addObject("backURI",
				"/comunidad/administrator/edit.do?comunidadId=" + comunidadId);

		return result;
	}

	@RequestMapping(value = "/vecinoMorosoList", method = RequestMethod.GET)
	public ModelAndView vecinoMorosList(@RequestParam int vecinoId) {
		ModelAndView result;
		Collection<Acta> actas;
		Boolean isMoroso;

		isMoroso = true;
		actas = actaService.findActasMorosoByVecinoMoroso(vecinoId);

		result = new ModelAndView("acta/morosoList");
		result.addObject("requestURI", "acta/administrator/vecinoMorosoList.do");
		result.addObject("actas", actas);
		result.addObject("isMoroso", isMoroso);
		result.addObject("backURI", "/vecino/administrator/edit.do?vecinoId="
				+ vecinoId);

		return result;
	}

	@RequestMapping(value = "/morososList", method = RequestMethod.GET)
	public ModelAndView morosoList(@RequestParam int comunidadId) {
		ModelAndView result;
		Collection<Acta> actas;

		actas = actaService.findActasMorosoByComunidadDeVecinos(comunidadId);

		result = new ModelAndView("acta/morosoList");
		result.addObject("requestURI", "acta/morosoList.do");
		result.addObject("backURI",
				"/comunidad/administrator/edit.do?comunidadId=" + comunidadId);
		result.addObject("actas", actas);

		return result;
	}

}
